package com.taotao.sso.controller;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.sso.pojo.User;
import com.taotao.sso.service.UserService;

@RequestMapping("user")
@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	

	
	
	
	
	@RequestMapping(value="login",method=RequestMethod.GET)
	@ResponseBody
	public void login(HttpServletRequest request,HttpServletResponse response){
		try {
		
			
			String ticket=this.userService.login(request);
		
			
			
			ServletOutputStream out = response.getOutputStream();
			out.write(ticket.getBytes("utf-8"));
		} catch (Exception e) {
		
			e.printStackTrace();
		
		}
		
	}
	
	@RequestMapping(value="timeout",method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> TimeOut(HttpServletRequest request){
		
		HttpSession session=request.getSession();
		if(session.getAttribute("hello")==null){
		
				session.setAttribute("sj", "失效了");
			
		}
		
		return ResponseEntity.status(HttpStatus.OK).body((String)session.getAttribute("sj"));
	
		
	}
	
	

}
